package collection.frame;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ComparatorText {

	public static void main(String[] args) {
		textComparatorCompare();

	}

	private static void textComparatorCompare() {
		List<Integer> ls = new ArrayList<Integer>();
		ls.add(1);
		ls.add(3);
		ls.add(6);
		ls.add(6);
		ls.add(8);
		ls.add(7);
		ls.add(4);
		ls.add(2);
		ls.add(0);

		for (int i = 0; i < ls.size(); i++) {
			System.out.println("index i = " + ls.get(i).intValue());
		}
		Collections.sort(ls, new ComparatorCompare());
		System.out.println("ComparatorCompared ");
		for (int i = 0; i < ls.size(); i++) {
			System.out.println("index i = " + ls.get(i).intValue());
		}

	}

}

class ComparatorCompare implements Comparator<Integer> {

	@Override
	public int compare(Integer l, Integer r) {
		int result = 0;
		if (l.intValue() > r.intValue()) {
			result = 1;
		} else if (l.intValue() < r.intValue()) {
			result = -1;
		}
		return result;
	}
}